package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.entity.MqModeResult;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DeviceWorkModeReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,V4,MODE,098745,m2,400,145306,A,2250.2214,N,11391.6105,E,0.18,281,030621,FDFFFFFF
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];//指令标识，流水号或者时间
        String modeSeq = split[5].substring(1);//设备的工作模式序号
        String interval = split[6];//主动上传间隔时间
        String deviceTime = split[7];//设备回复的时间
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqModeResult mqModeResult = new MqModeResult();
        mqModeResult.setCommandNumber(commandNumber);
        mqModeResult.setDeviceDate(deviceDate);
        mqModeResult.setDeviceTime(deviceTime);
        mqModeResult.setImei(imei);
        mqModeResult.setInterval(Integer.parseInt(interval));
        mqModeResult.setMode(Integer.parseInt(modeSeq));
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqModeResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().modeResponse(mqModeResult);
        return imei;
    }
}
